/*
 * @Author: yushanghui
 * @description: 
 * @param: 
 * @Date: 2020-04-27 18:02:30
 * @LastEditTime: 2020-04-29 14:23:57
 */
import http from "service/canpintupu";

//轮播图
const canpintupuStore = {
  state: {
    canPinLists:{},
    hotLists:[],
    categoryList:[],
    tupuDetail:{}
  },
  reducers: {
    changeCanPinList: (state, canPinLists, type) => ({
      ...state,
      ...canPinLists
    }),
    changeCategoryList: (state, categoryList) => ({
      ...state,
      ...categoryList
    }),
    
    changeCanHotLists: (state, hotLists) => ({
      ...state,
      ...hotLists
    }),
    changeDetail: (state, tupuDetail) => ({
      ...state,
      ...tupuDetail
    }),
  },
  effects: {
    async getCanPinList (json) {
      let newJson = {
        current: json.current,
        name: json.name
      }
      let canPinLists = await http.getCanPinTuPuList(newJson);
      if (canPinLists.categoryList) {
        let categoryList = canPinLists.categoryList
        this.changeCategoryList({ categoryList})
      }
      if (!canPinLists.graphList.length) {
        canPinLists.isend = true
      }
      if (json.graphList) {
        canPinLists.graphList = [...json.graphList, ...canPinLists.graphList]
      }
      this.changeCanPinList({ canPinLists });
    },
    async getHotTuPuLists () {
      let hotLists = await http.getHotTuPuList();
      this.changeCanHotLists({ hotLists });
    },
    async getDetail (id) {
      let tupuDetail = await http.getTuPuDetail(id);
      this.changeDetail({ tupuDetail });
    },
    
  }
};

export default canpintupuStore;
